//
//  YTStudyAllViewController.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/11/20.
//

#import "YTStudyAllViewController.h"
#import "YTStudySearchViewController.h"
#import "YTStudyViewController.h"
#import "YTStudyViewController.h"
#import "YTExpertListViewController.h"
#import "YTExpertSearchViewController.h"

@interface YTStudyAllViewController ()


@property (nonatomic ,strong) UIButton * XXBtn;
@property (nonatomic ,strong) UIButton * ZJBtn;
@property (nonatomic ,strong) UIView * Btnmakeview;
///当前是否是专家
@property (nonatomic ,assign) BOOL isOpenXX;
@property (nonatomic ,assign) BOOL isfirst;

@property (nonatomic ,strong) YTStudyViewController * XXVC;
@property (nonatomic ,strong) YTExpertListViewController * ZJVC;
@property (nonatomic ,strong) UIView * topview;
@end

@implementation YTStudyAllViewController
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if (self.isfirst) {
        if(self.isOpenXX){
            [self.XXVC refreshingData];
        } else {
            [self.ZJVC refreshingData];
        }
    }
    self.isfirst = YES;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupView];
}

- (void)setupView{
    self.view.backgroundColor = KcolorHex(@"#ECEDEE");

    UIView * topview = [UIView new];
    topview.backgroundColor = KcolorHex(@"#0967FF");
    [self.view addSubview:topview];
    [topview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.offset(0);
        make.height.offset(KTop + kwt(56));
    }];
    self.topview = topview;
    
    UIView * topbtnview = [UIView new];
    topbtnview.backgroundColor = KcolorHex(@"#3284FB");
    [topview addSubview:topbtnview];
    [DTKTool YJ:kwt(8) andView:topbtnview];
    [topbtnview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.height.offset(kwt(37));
        make.centerY.offset(KTop/2);
        make.width.offset(kwt(250));
    }];
    
    UIView * Btnmakeview = [UIView new];
    self.Btnmakeview = Btnmakeview;
    Btnmakeview.backgroundColor = UIColor.whiteColor;
    [topbtnview addSubview:Btnmakeview];
    [DTKTool YJ:kwt(8) andView:Btnmakeview];
    Btnmakeview.frame = CGRectMake(0, 0, kwt(125), kwt(37));
    
    MJWeakSelf
    UIButton * XXBtn = [UIButton buttonWithType:0];
    self.XXBtn = XXBtn;
    XXBtn.addFont(kFont(19)).addNormalText(@"学习").addNormalColor(KcolorHex(@"#0967FF")).addTarget(self,@selector(openXX));
    [topbtnview addSubview:XXBtn];
    [XXBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.top.offset(0);
    }];
    
    UIButton * ZJBtn = [UIButton buttonWithType:0];
    self.ZJBtn = ZJBtn;
    ZJBtn.addFont(kFont(19)).addNormalText(@"专家").addNormalColor(KcolorHex(@"#0967FF")).addTarget(self,@selector(openZJ));
    [topbtnview addSubview:ZJBtn];
    [ZJBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.right.top.offset(0);
        make.left.equalTo(XXBtn.mas_right);
        make.width.equalTo(XXBtn);
    }];
    
    UIButton * ssbtn = [UIButton buttonWithType:0];
    ssbtn.addimg([UIImage imageNamed:@"seach"]).addTarget(self,@selector(openSS));
    [topview addSubview:ssbtn];
    [ssbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-15));
        make.height.width.offset(kwt(30));
        make.centerY.equalTo(topbtnview);
    }];
    
    [self openXX];
 
}
- (YTStudyViewController *)XXVC{
    if(!_XXVC){
        _XXVC = [YTStudyViewController new];
        [self addChildViewController:_XXVC];
        [self.view addSubview:_XXVC.view];
        [_XXVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.topview.mas_bottom);
            make.left.right.bottom.offset(0);
        }];
    }
    return _XXVC;
}
- (YTExpertListViewController *)ZJVC{
    if(!_ZJVC){
        _ZJVC = [YTExpertListViewController new];
        [self addChildViewController:_ZJVC];
        [self.view addSubview:_ZJVC.view];
        [_ZJVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.topview.mas_bottom);
            make.left.right.bottom.offset(0);
        }];
    }
    return _ZJVC;
}
///打开学习
- (void)openXX{
    if(self.isOpenXX == NO){
        self.isOpenXX = YES;
        [UIView animateWithDuration:0.25 animations:^{
            self.Btnmakeview.frame = CGRectMake(0, 0, kwt(125), kwt(37));
        } completion:^(BOOL finished) {
            self.XXBtn.addFont(kCFont(19)).addNormalColor(KcolorHex(@"#0967FF"));
            self.ZJBtn.addFont(kFont(19)).addNormalColor(UIColor.whiteColor);
            self.ZJVC.view.hidden = YES;
            self.XXVC.view.hidden = NO;
            [self.XXVC refreshingData];
        }];
    }
}
///打开专家
- (void)openZJ{
    
    if(self.isOpenXX ){
        self.isOpenXX= NO;
        [UIView animateWithDuration:0.25 animations:^{
            self.Btnmakeview.frame = CGRectMake(kwt(125), 0, kwt(125), kwt(37));
        } completion:^(BOOL finished) {
            self.XXBtn.addFont(kFont(19)).addNormalColor(UIColor.whiteColor);
            self.ZJBtn.addFont(kCFont(19)).addNormalColor(KcolorHex(@"#0967FF"));
            
            self.ZJVC.view.hidden = NO;
            self.XXVC.view.hidden = YES;
            [self.ZJVC refreshingData];
        }];
    }
}
///打开搜索
- (void)openSS{
    if(self.isOpenXX){
        YTStudySearchViewController * vc = [YTStudySearchViewController new];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    } else {
        YTExpertSearchViewController * vc = [YTExpertSearchViewController new];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }
     
}
@end
